from goods_info.models import *
from rest_framework.serializers import ModelSerializer
from rest_framework import serializers
class  CategorySerializer(ModelSerializer):

    '''

    商品类别列表的序列化类
    '''
    children=serializers.SerializerMethodField(read_only=True)


    class Meta:
        model=GoodsCategoryModel
        fields='__all__'

    #将父类别下子类别也返回，传递的是树形json格式
    def get_children(self,obj):
        if obj.children:
            return  CategorySerializer(obj.children,many=True).data

        else:
            return  None


